define([], function () {
    function initialize() {
        var viewModel = {
            boxes: [
                {
                    title: '功能列表', type: 'buttonGroup', buttons: [
                    {name: '案件完善', css: 'layui-btn-primary layui-bg-gray', number: 130},
                    {name: '新增案件', css: 'layui-btn-primary layui-bg-gray', number: 50},
                    {name: '案件申报', css: '', number: 100},
                    {name: '案件核查', css: '', number: 20},
                    {name: '案件审批', css: '', number: 40},
                    {name: '案件协查', css: 'layui-btn-normal', number: 5},
                    {name: '集群战役', css: 'layui-btn-warm', number: 2},
                    {name: '弹出框演示', css: 'layui-btn-primary', number: 0}
                ]
                },
                {
                    title: '案件处理', type: 'panelGroup', panels: [
                    {name: '新增案件', number: '100'},
                    {name: '协查案件', number: '20'},
                    {name: '受理案件', number: '120'},
                    {name: '立案案件', number: '20'},
                    {name: '侦查案件', number: '22'},
                    {name: '破获案件', number: '220'},
                    {name: '归档案件', number: '1020'}
                ]
                },
                {
                    title: '案件督办', type: 'panelGroup', panels: [
                    {name: '申报案件', number: '100'},
                    {name: '核查案件', number: '20'},
                    {name: '审批案件', number: '40'}
                ]
                }
            ]
        };

        var dialogNormalContent = '1111';
        var dialogMaxContent = '2222222222';

        viewModel.clickBtn = function (btn) {
            if (btn.name == '弹出框演示') {
                layer.open({
                    type: 1,
                    title: '<i class="layui-icon" style="font-size: 30px; color: #FF5722;">&#xe756;</i> 即将超期的案件',
                    area: '300px;',
                    shade: 0,
                    id: 'willOverdue',
                    btn: ['马上处理', '稍后处理'],
                    btnAlign: 'c',
                    moveType: 1,
                    maxmin: true,
                    content: dialogNormalContent,
                    yes: function (index) {
                        layui.layer.full(index);
                        $('#willOverdue').html(dialogMaxContent);
                        return false;
                    },
                    btn2: function (index) {
                        try {
                            layui.layer.restore(index);
                            $('#willOverdue').html(dialogNormalContent);
                        } catch (e) {
                        }
                        layui.layer.min(index);
                        return false;
                    },
                    cancel: function (index, layero) {
                        layer.confirm('确定已经处理完毕了么？', {icon: 3, title: '提示'}, function (index2) {
                            layui.layer.close(index2);
                            layui.layer.close(index);
                        });
                        return false;
                    },
                    full: function () {
                        $('#willOverdue').html(dialogMaxContent);
                    },
                    restore: function () {
                        $('#willOverdue').html(dialogNormalContent);
                    }
                });
            }
        };

        viewModel.clickCollaItem = function (data, event) {
            $('.layui-colla-item .layui-layout-right').hide();
            for (var i = 0, len = $('.my-box').length; i < len; i++) {
                if ($($('.my-box')[i]).find('.layui-show').length == 0) {
                    $($('.my-box')[i]).removeClass('layui-col-xs12');
                    $($('.my-box')[i]).addClass('layui-col-xs2');
                }
            }
            setTimeout(function () {
                if ($(event.currentTarget).parents().find('.layui-show').length > 0) {
                    $(event.currentTarget).find('.layui-layout-right').show();
                    $(event.currentTarget).parent().removeClass('layui-col-xs2');
                    $(event.currentTarget).parent().addClass('layui-col-xs12');
                }
            }, 100);
        };

        setTimeout(function () {
            layui.element.render();
            for (var i = 0, len = viewModel.boxes.length; i < len; i++) {
                if (viewModel.boxes[i].type == 'panelGroup') {
                    for (var j = 0, len2 = viewModel.boxes[i].panels.length; j < len2; j++) {
                        layui.laypage.render({
                            elem: 'pagination-id-' + viewModel.boxes[i].title + '-' + j,
                            count: 100,
                            layout: ['limit', 'prev', 'next', 'skip'],
                            jump: function (obj) {
                            }
                        });
                    }
                }
            }
        }, 300);

        return viewModel;
    }

    return {
        initialize: initialize
    }
});